package demo3;

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        //输入
        Scanner in = new Scanner(System.in);
        String n = in.nextLine();
        int t = Integer.parseInt(n);
        String[] strs = new String[t];
        for(int i = 0; i < t; i++) {
            strs[i] = in.nextLine();
        }
        //处理
        for(int i = 0; i < t; i++) {//拿到每一条指令
            String str = strs[i];
            int l = 0;
            int r = 0;
            char now = 0;//当前方向
            int index = 0;//指针
            int len = str.length();
            while(index < len) {
                StringBuilder left = new StringBuilder();
                StringBuilder right = new StringBuilder();
                //先找出最终指向
                while(index < len && (str.charAt(index) == 'R' || str.charAt(index) == 'L')) {
                    now = str.charAt(index);
                    index++;
                }
                //开始行驶
                while(index < len && (str.charAt(index) >= '0' && str.charAt(index) <= '9')) {
                    if(now == 'L') {
                        left.append(str.charAt(index));
                    } else {
                        right.append(str.charAt(index));
                    }
                    index++;
                }
                //转换位数字
                if(now == 'L') {
                    l += Integer.parseInt(left.toString());
                } else {
                    r += Integer.parseInt(right.toString());
                }
            }
            //计算
            double ret = Math.sqrt((l*l + r*r) * 1.0);
            System.out.println(ret);
        }
    }
}
